<?php

# this script grabs the html files from $rooturl and copy them to local folder, this localfolder should also  be defined at temp.php 

   $rooturl="http://carocoops.org/secoora_data/latest/all_obs/html_tables/html_tables/";
   $localfolder="data/";

           $nos_array=array(8651370,8656483,8652587,8668498,8665530,8664941,8662245,8661070,8659897,8659084,8658120,8658163);
           $nos_array1=array("nos.8651370.wl.htm","nos.8656483.wl.htm","nos.8652587.wl.htm","nos.8668498.wl.htm","nos.8665530.wl.htm","nos.8664941.wl.htm","nos.8662245.wl.htm","nos.8661070.wl.htm","nos.8659897.wl.htm","nos.8659084.wl.htm","nos.8658120.wl.htm","nos.8658163.wl.htm");
           $nos_url="http://tidesandcurrents.noaa.gov/station_info.shtml"; 

           $ndbc_array=array("DUCN7","41025","CLKN7","41013","41004","FBIS1","41002");
           $ndbc_array1=array("ndbc.DUCN7.met.htm","ndbc.41025.met.htm","ndbc.CLKN7.met.htm","ndbc.41013.met.htm","ndbc.41004.met.htm","ndbc.FBIS1.met.htm","ndbc.41002.met.htm");
           $ndbc_url="http://www.ndbc.noaa.gov/station_page.php";

           $nws_array=array("KEDE","KECG","KFFA","KMQI","KHSE","KOCW","KEWN","KNKT","KMRH","KNJM","KNCA","KOAJ","KILM","KSUT","KCRE","KMYR","KCHS","KASJ","KPGV");
           $nws_array1=array("nws.kede.metar.htm","nws.KECG.metar.htm","nws.KFFA.metar.htm","nws.KMQI.metar.htm","nws.KHSE.metar.htm","nws.KOCW.metar.htm","nws.KEWN.metar.htm","nws.KNKT.metar.htm","nws.KMRH.metar.htm","nws.KNJM.metar.htm","nws.KNCA.metar.htm","nws.KOAJ.metar.htm","nws.KILM.metar.htm","nws.KSUT.metar.htm","nws.KCRE.metar.htm","nws.KMYR.metar.htm","nws.KCHS.metar.htm","nws.KASJ.metar.htm","nws.KPGV.metar.htm");

            $rcoos_array=array("FRF-17mwaverider","FRF-8mAWAC","FRF-8mAWAC","FRF-JennettePier","FRF-Met","FRF-AlbemarleSound","FRF-8marray","FRP2","ILM2","ILM3","OCP1","LEJ2","LEJ3","CAP1","CAP2","CAP3","FRP1","FRP2","SUN2","SUN3","FollyBeach","Springmaid","NCCOOS-Jennette Pier","NCCOOS-Bogue-Inlet-Pier","NCCOOS-Lookout-shoals-Research-Buoy","nerr-niwol","nerr-acesp","nerr-nocrc");
           $rcoos_array1=array("FRF-17mwaverider","FRF-8mAWAC","FRF-8mAWAC","FRF-JennettePier","FRF-Met","FRF-AlbemarleSound","FRF-8marray","carocoops.FRP2.buoy.htm","cormp.ILM2.buoy.htm","cormp.ILM3.buoy.htm","cormp.OCP1.buoy.htm","cormp.LEJ2.buoy.htm","cormp.LEJ3.buoy.htm","carocoops.CAP1.buoy.htm","carocoops.CAP2.buoy.htm","carocoops.CAP3.buoy.htm","carocoops.FRP1.buoy.htm","carocoops.FRP2.buoy.htm","carocoops.SUN2.buoy.htm","carocoops.SUN3.buoy.htm","FollyBeach","Springmaid","NCCOOS-Jennette Pier","NCCOOS-Bogue-Inlet-Pier","NCCOOS-Lookout-shoals-Research-Buoy","nerr-niwol","nerr-acesp","nerr-nocrc");
            
        
         for($i=0;$i<count($nos_array);$i++){
            $remotefile=strtolower($nos_array1[$i]);
            $remotefile=$rooturl.$remotefile;
            $handle=fopen($remotefile,"r");
            if($handle){
                $localfile = $localfolder.$nos_array[$i].".htm";
                $content=fread($handle,8000);
                $fh = fopen($localfile, 'w') ;
                if($fh){fwrite($fh, "NOS Station:$nos_array[$i]");fwrite($fh, $content);}
                fclose($fh);
                fclose($handle);
            }
         }
         for($i=0;$i<count($nws_array);$i++){
            $remotefile=strtolower($nws_array1[$i]);
            $remotefile=$rooturl.$remotefile;
            $handle=fopen($remotefile,"r");
            if($handle){
                $localfile = $localfolder.$nws_array[$i].".htm";
                $content=fread($handle,8000);
                $fh = fopen($localfile, 'w') ;
                if($fh){fwrite($fh, "NWS Station:$nws_array[$i]");fwrite($fh, $content);}
                fclose($fh);
                fclose($handle);
            }
         }        
        for($i=0;$i<count($ndbc_array);$i++){
            $remotefile=strtolower($ndbc_array1[$i]);
            $remotefile=$rooturl.$remotefile;
            $handle=fopen($remotefile,"r");
            if($handle){
                $localfile = $localfolder.$ndbc_array[$i].".htm";
                $content=fread($handle,8000);
                $fh = fopen($localfile, 'w') ;
                if($fh){fwrite($fh, "NDBC Station:$ndbc_array[$i]");fwrite($fh, $content);}
                fclose($fh);
                fclose($handle);
            }
         }       
        for($i=0;$i<count($rcoos_array);$i++){
            $remotefile=strtolower($rcoos_array1[$i]);
            $remotefile=$rooturl.$remotefile;
            $handle=fopen($remotefile,"r");
            if($handle){
                $localfile = $localfolder.$rcoos_array[$i].".htm";
                $content=fread($handle,8000);
                $fh = fopen($localfile, 'w') ;
                if($fh){fwrite($fh, "RCOOS Station:$rcoos_array[$i]");fwrite($fh, $content);}
                fclose($fh);
                fclose($handle);
            }
         }        

?>
